﻿using System.IO;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using zhangmenren.Service;
using zhangmenren.Untils;
using Microsoft.Extensions.Logging;

namespace zhangmenren
{
	public class Startup
	{
		public Startup(IConfiguration configuration)
		{
			Configuration = configuration;
		}

		public IConfiguration Configuration { get; }

		// This method gets called by the runtime. Use this method to add services to the container.
		public void ConfigureServices(IServiceCollection services)
		{
			services.Configure<CookiePolicyOptions>(options =>
			{
				// This lambda determines whether user consent for non-essential cookies is needed for a given request.
				options.CheckConsentNeeded = context => false;
				options.MinimumSameSitePolicy = SameSiteMode.None;
			});

			services.AddTransient<IService.IAdminService, AdminService>();
			services.AddTransient<IService.IBannerService, BannerService>();
            services.AddTransient<IService.IUserService, UserService>();
			services.AddTransient<IService.ICacheService, MemoryCacheService>();
            services.AddTransient<IService.IEnterpriseService, EnterpriseService>();
            services.AddTransient<IService.IClassMSGService, ClassMSService>();
            services.AddTransient<IService.IWorksService, WorksService>();
            services.AddTransient<IService.IChapterService, ChapterService>();
            services.AddTransient<IService.ICensusService, CensusService>();
            services.AddTransient<IService.ICommentServic, CommentService>();
            services.AddTransient<IService.IRealService, RealService>();
			services.AddTransient<IService.IApplyService, ApplyService>();
			services.AddTransient<IService.IOrderService, OrderService>();
			services.AddTransient<IService.IQiYeService, QiYeService>();
            services.AddTransient<IService.IProductService, ProductService>();
            services.AddTransient<IService.IItemService, ItemService>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
		}

		// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
		public void Configure(IApplicationBuilder app, IHostingEnvironment env)
		{
			if (env.IsDevelopment())
			{
				app.UseDeveloperExceptionPage();
			}
			else
			{
				app.UseExceptionHandler("/Home/Error");
				app.UseHsts();
			}

			app.UseHttpsRedirection();
			app.UseStaticFiles();
			app.UseCookiePolicy();
			app.UseAuthentication();


            app.UseMvc(routes =>
			{
				routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action=Index}/{id?}");

				routes.MapRoute(
					name: "default",
					template: "{controller=Home}/{action=Index}/{id?}");
			});
		}
	}
}
